using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Publishing.Fields;

namespace SharePoint.DataMapper
{
	[FieldMapper(typeof(HtmlField))]
	public class FieldHtmlMapper : FieldMapper
	{
		protected override SPField AddFieldInternal(ListDataContext context, SPFieldCollection collection, Type propertyType, FieldAttribute attribute)
		{
			string name = collection.Add(new HtmlField(collection, attribute.Field));
			SPField field = collection.GetFieldByInternalName(name);
			SetFieldPropertiesInternal(field, attribute);
			return field;
		}

		protected override FieldAttribute GetFieldAttributeInternal(SPField field)
		{
			FieldAttribute attribute = base.GetFieldAttributeInternal(field);
			attribute.FieldMapper = typeof(FieldHtmlMapper);
			return attribute;
		}
	}
}